package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC779 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[] base = {0, 1};

        public int kthGrammar(int n, int k) {
            return kthGrammarRecur(n, k, false);
        }

        public int kthGrammarRecur(int n, int k, boolean rev) {
            if (n == 1) return rev ? 1 : 0;
            rev = k % 2 == 0 ? !rev : rev;
            return kthGrammarRecur(n - 1, (k + 1) / 2, rev);
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.kthGrammar(4, 5));
    }

    public static void main(String[] args) throws Exception {
        LC779 an = new LC779();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
